package test;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
	 public static void displayAll(){	 
		 String URL = "jdbc:mysql://localhost:3306/test";
			String driverName = "com.mysql.jdbc.Driver";
			String sql = "select * from students";
			String userName = "root";//root
			String password = "kfc123456";//123456
			Connection conn = null;
			//201521123059
			try {
				Class.forName(driverName);
			} catch (ClassNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}//jdbc4.0 ������ʹ������������ע�����
			
			
			try {
				conn = DriverManager.getConnection(URL,userName,password);
				Statement statement = conn.createStatement();
				ResultSet resultSet = statement.executeQuery(sql);
				// id | stuno     | name | gender | birthdate  | major
				while(resultSet.next()){
					int id = resultSet.getInt("id");
					String stuno = resultSet.getString("stuno");
					Date date = resultSet.getDate("birthdate");
					System.out.print("id="+id+" stuno="+stuno+" birthdate="+date);
					System.out.println();
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
				if(conn!=null)
					try {
						conn.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}//����ʹ��Try..with..resources�﷨��
				conn = null;
			}
	 }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		displayAll();

	}

}
